package com.linkoog.devtools.json.toolwindow.ui.jsontree;

import com.intellij.ui.ColoredTableCellRenderer;
import com.intellij.ui.treeStructure.treetable.TreeTable;
import com.intellij.ui.treeStructure.treetable.TreeTableTree;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import javax.swing.tree.TreePath;

public class TableKeyRenderer extends ColoredTableCellRenderer {


    @Override
    protected void customizeCellRenderer(@NotNull JTable table, @Nullable Object value, boolean selected, boolean hasFocus, int row, int column) {
        if (table instanceof TreeTable){
            TreeTable treeTable = (TreeTable)table;
            final TreeTableTree tree = treeTable.getTree();
            TreePath pathForRow = tree.getPathForRow(row);
            JsonTreeNode node = (JsonTreeNode) pathForRow.getLastPathComponent();
            this.append(node.getName(), TreeStyles.indexAttribute);
        }
    }
}
